from django.contrib import admin
from psd.register.models import Person, RegRecord, BreakRecord, DateRecord, MatchRecord, Event
from psd.register.forms import MatchRecordForm, PersonForm, RegRecordForm, DateRecordForm

## For some reason, using 'gender' in list_display shows the full name ('male', 'female')
## if a person has one gender, and 'None' if they have several. This works better.
def gender(p):
    return p.gender

class MyPerson(admin.ModelAdmin):
    form = PersonForm
    list_display = (unicode, 'psdid', 'age', gender)
    list_filter = ('gender',)
    search_fields = ['psdid', 'first_name', 'last_name']

class MyDateRecord(admin.ModelAdmin):
    form = DateRecordForm
    search_fields = ['psdid','other_psdid']
    list_filter = ('event',)
    fields = ('psdid', 'other_psdid', 'friend_date', 'said_yes', 'they_said_yes', 'event', 'table', 'round', 'notes')


class MyMatchRecord(admin.ModelAdmin):
    form = MatchRecordForm
    search_fields = ['psdid1','psdid2']
    list_filter = ('event',)
    
    
class MyReg(admin.ModelAdmin):
    form = RegRecordForm
    list_filter = ('paid','cancelled','here','event','matches')
    search_fields = ['psdid', 'email']
    exclude = ('geek_code','matches', 'oneway','people',)
    list_display = ('__unicode__', 'matches')
    fieldsets = [(None, {'fields':['event','psdid','nickname','email']}),
              ('Admin', {'fields':['add_to_mailings', 'here', 'paid', 'pending', 'cancelled','stationary']}),
              ('Dating',{'fields':['friend_dates', 'groups_match_all', 'seek_groups', 'location']}),
              ('Children',{'fields':['wants_childcare','children'], 'classes':['collapse']}),
              (None, {'fields':['comments','notes']}) ]

class MyEvent(admin.ModelAdmin):
    list_filter = ('date',)
    
    
# class PersonInline(admin.StackedInline):
#    model = Person
#    extra = 3
# 
# class RegRecAdmin(admin.ModelAdmin):
   # inlines = [PersonInline]
   # fieldsets = [
   #     (None,               {'fields': ['question']}),
   #     ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
   # ]

#admin.site.register(RegRecord, RegRecAdmin)



admin.site.register(Person, MyPerson)
admin.site.register(RegRecord, MyReg)
admin.site.register(DateRecord, MyDateRecord)
admin.site.register(MatchRecord, MyMatchRecord)
admin.site.register(BreakRecord)

admin.site.register(Event, MyEvent)
